home *** CD-ROM | disk | FTP | other *** search
/ The Best Shareware of the Year 1997 Winter / The Best Shareware of the Year 1997 Winter.iso / dist / wm / wmfiles / 9603mar / progwin / code.txt
Encoding:
Text File  |  1996-01-26  |  1.4 KB  |  40 lines

  1. //Underpinnings for an Object Model
  2. class IUnknown {
  3. public:
  4.     virtual ULONG AddRef() = 0;
  5.     virtual ULONG Release() = 0;
  6.     virtual HRESULT QueryInterface(
  7.      REFIID iid, void** ppvObj) = 0;
  8.     };
  9.  
  10. //Calling a COM Object's Methods
  11. IMyInterface* pMy = NULL;
  12. if (pUnknown->QueryInterface(
  13.      IID_IMyInterface,
  14.     (void**)&pMy) == NOERROR){
  15.     pMy->MyMethod(parameters);
  16.     pMy->Release();    
  17.     }
  18.  
  19. Interface Map Basics
  20. To implement a class using MFC's interface maps follow these steps:
  21.  1.    Derive a class either directly or indirectly from CCmdTarget.
  22.  2.    Use the DECLARE_INTERFACE_MAP function in the derived class
  23. definition.
  24.  3.    For each interface you wish to support, use the
  25. BEGIN_INTERFACE_PART and END_INTERFACE_PART macros in the class
  26. definition.
  27.  4.    In the implementation file, use the BEGIN_INTERFACE_MAP and
  28. END_INTERFACE_MAP macros to define the class's interface map.
  29.  5.    For each IID supported, use the INTERFACE_PART macro between
  30. the BEGIN_INTERFACE_MAP and END_INTERFACE_MAP macros to map that IID
  31. to a specific "part" of your class.
  32.  6.    Implement each of the nested classes that represent the
  33. interfaces you support.
  34.  7.    Use the METHOD_PROLOGUE macro to access the parent,
  35. CCmdTarget-derived object.
  36.  8.    AddRef, Release, and QueryInterface can delegate to the
  37. CCmdTarget implementation of these functions (ExternalAddRef,
  38. ExternalRelease, and ExternalQueryInterface).
  39.  
  40.